// Copyright 2011 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


/**
 * @fileoverview Unit tests for shellExtension.utils.
 *
 * Test cases:
 *   testInEnum
 *   testIsTypeArray
 *   testIsType
 *
 * @author jasonstredwick@google.com (Jason Stredwick)
 */


goog.require('shellExtension.utils');


/**
 * Tests inEnum to ensure it can properly match the given valeus.
 */
function testInEnum() {
  var inEnum = shellExtension.utils.inEnum;

  // Bad inputs
  assertFalse('1', '', ''); // Invalid object/enum type.
  assertFalse('2', 3, {}); // Invalid data type.

  // Data present.
  assertTrue('3', 'value', {'a': 'a', 'b': 'value', 'c': 'c'});

  // Data not present.
  assertFalse('4', 'value', {'a': 'a', 'c': 'c'});
}


/**
 * Tests isTypeArray to ensure it can properly match the given types.
 */
function testIsTypeArray() {
  var isTypeArray = shellExtension.utils.isTypeArray;

  // Bad inputs
  assertFalse('1', '', ''); // obj is not of type object.
  assertFalse('2', {}, ''); // obj has no length property.
  // Array-like object is inconsistent between length to keys.
  assertFalse('3', {'length': 3, '0': 0, '1': 1}, 'number');
  // Array-like object does not have consecutive keys.
  assertFalse('4', {'length': 2, '0': 0, '2': 2}, 'number');

  // Test Array
  assertTrue('5', [1, 2, 3], 'number');

  // Test that empty arrays don't care about the type.
  assertTrue('6', [], 'number');
  assertTrue('7', [], 'string');

  // Test Array-like object.
  assertTrue('8', {'length': 2, '0': 0, '1': 1}, 'number');
}


/**
 * Tests isType to ensure it can properly match the types.
 */
function testIsType() {
  var isType = shellExtension.utils.isType;

  // Bad type input.
  assertFalse('1', 'input', null); // type must be a string.

  // Test null.
  assertTrue('2', null, 'null');
  assertFalse('3', null, 'object');

  // Test standard types.
  assertTrue('4', '', 'string');
  assertTrue('5', 3, 'number');
  assertTrue('6', {}, 'object');
  assertTrue('7', [], 'object');
  assertTrue('8', function() {}, 'function');
  assertTrue('9', undefined, 'undefined');
}

